<?php if ($error==1):?>
<div id="msg"><?php echo 'Invalid data';?></div>
<?php else:?>
<div id="msg" class="hidden"></div>
<?php endif;?>
<form action="/data/save" method="POST" id="frmData" name='frmData'>
	<div class="frm">
		<dl class="clear">
			<dt><label>User ID: </label></dt>
			<dd>
				<input type="text" class="text" id="user_id" name="user_id" onchange="checkUserId()" />
				<input type="button" class="button" value="Check user" onclick="checkUserId()" />
			</dd>
		</dl>
		<dl class="clear" id="user_name_field">
			<dt><label>User name: </label></dt>
			<dd><input type="text" class="text" id="user_name" name="user_name" /></dd>
		</dl>
		<dl class="clear hidden" id="user_avatar_field">
			<dt>&nbsp;</dt>
			<dd></dd>
		</dl>
		<dl class="clear">
			<dt><label>Data ID: </label></dt>
			<dd><textarea class="text" id="data" name="data" cols="30" rows="5"></textarea></dd>
		</dl>
		<dl class="clear">
			<dt>&nbsp;</dt>
			<dd><input type="button" value="Submit" onclick="submitData()" /></dd>
		</dl>
	</div>
</form>

<style type="text/css">
	.frm dt {width:100px}
	.frm dd {margin-left:10px}
</style>

<script type="text/javascript">
<!--
function checkUserId(callback) {
	$('#msg').text('checking user').show();
	$.ajax({
		url:"/data/check_user",
		type:"POST",dataType:"json",
		data:{user_id:$("#user_id")[0].value},
		success:function(result) {
			$('#user_avatar_field').hide();
			if (!result.error) {
				if (result.param.user_name != null) {
					$('#user_name').attr('value', result.param.user_name);
					$('#user_name').attr('disabled', true);
					
					$('#user_avatar_field dd').html('<img src="' + result.param.image_url +'" alt="" />');
					$('#user_avatar_field').show();
					
					$('#msg').hide();
					if (callback) eval('callback()');
				}
				else {
					$('#msg').text('Can\'t find user name. Please enter new data entry').show();
					$('#user_name').attr('disabled', false);					
				}
				$('#user_name_field').show();
			}
			else $('#msg').text(result.message).show();
		}
	});
}

function submitData() {
	if ($('#user_name').attr('value')!='') {
		$('#user_name').attr('disabled', false); //enable again to submit
		$('#frmData').submit();
	}
	else {
		$('#msg').text("Please enter username").show();
	}
}
-->
</script>